Imports System.IO
Imports MasterCms.CTools
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary

Partial Class kommentar
    Inherits System.Web.UI.UserControl
    Private mSeite As String
    Private mAnzeigen As Boolean

    Public Property Seite() As String
        Get
            Seite = mSeite
        End Get
        Set(ByVal value As String)
            mSeite = value
        End Set
    End Property
    Public Property Anzeigen() As Boolean
        'zeitgesteuertes Anzeigen
        Get
            Anzeigen = mAnzeigen
        End Get
        Set(ByVal value As Boolean)
            mAnzeigen = value
        End Set
    End Property

    Private Sub Laden()


        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("mastercms").ConnectionString
        Dim tbPages = New cTbPages(strConn)

        Dim WhereKom As String
        If tbPages.GetFelder(Seite).Item(0).Item("kommentflag").ToString = "Ja" Then
            Dim Order As String = "Cnr DESC"
            WhereKom = "artref = " & Seite & " AND pagetyp = 'kom'"
            ' Kommentare
            AnzKommentare.Text = tbPages.GetDataSet(StrSelect:="content, creationdate, titel", strWhere:=WhereKom).Tables(0).DefaultView.Count.ToString
            Kommentare.DataSource = tbPages.GetDataSet(StrSelect:="content, creationdate, author", strWhere:=WhereKom, strOrder:=Order).Tables(0).DefaultView
            Kommentare.DataBind()
        End If


    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If mAnzeigen = True Then
                Laden()
                Zeige(False)
                Zeigeliste(True)
            End If
        End If
    End Sub
    Protected Sub Speichern_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsValid Then
            Insert()
            Response.Redirect("default.aspx?cms=" & Seite)
        End If
    End Sub

    Protected Sub Abbrechen_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("default.aspx?cms=" & Seite)
    End Sub

    Protected Sub KommentarSchreiben_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles KommentarSchreiben.Click
        Zeige(True)
    End Sub
    Private Sub Zeigeliste(ByVal Flag As Boolean)
        panListe.Visible = Flag
    End Sub
    Private Sub Zeige(ByVal Flag As Boolean)
        panLink.Visible = Not Flag
        panEinqabe.Visible = Flag
        'panListe.Visible = Flag
    End Sub
    Private Sub Insert()
        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("mastercms").ConnectionString
        Dim tbPages = New cTbPages(strConn)
        tbPages.Insert(Author:=texName.Text, Content:=texKommentar.Text, pagetyp:="kom", Artikelreferenz:=Seite)
    End Sub

    Protected Sub Kommentare_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles Kommentare.PageIndexChanging
        Kommentare.PageIndex = e.NewPageIndex
        Laden()
    End Sub
End Class
